|
1
|
|
|
import Helper from '../../src/Helper'; |
|
2
|
|
|
import InvalidInputError from '../../src/InvalidInputError'; |
|
3
|
|
|
|
|
4
|
|
|
const TestCasesResult = [ |
|
5
|
|
|
{ |
|
6
|
|
|
description: '[] = 0', |
|
7
|
|
|
input: [], |
|
8
|
|
|
expectedResult: 0, |
|
9
|
|
|
}, |
|
10
|
|
|
{ |
|
11
|
|
|
description: '000 = 0', |
|
12
|
|
|
input: [false, false, false], |
|
13
|
|
|
expectedResult: 0, |
|
14
|
|
|
}, |
|
15
|
|
|
{ |
|
16
|
|
|
description: '001 = 1', |
|
17
|
|
|
input: [false, false, true], |
|
18
|
|
|
expectedResult: 1, |
|
19
|
|
|
}, |
|
20
|
|
|
{ |
|
21
|
|
|
description: '010 = 1', |
|
22
|
|
|
input: [false, true, false], |
|
23
|
|
|
expectedResult: 1, |
|
24
|
|
|
}, |
|
25
|
|
|
{ |
|
26
|
|
|
description: '011 = 2', |
|
27
|
|
|
input: [false, true, true], |
|
28
|
|
|
expectedResult: 2, |
|
29
|
|
|
}, |
|
30
|
|
|
{ |
|
31
|
|
|
description: '100 = 1', |
|
32
|
|
|
input: [true, false, false], |
|
33
|
|
|
expectedResult: 1, |
|
34
|
|
|
}, |
|
35
|
|
|
{ |
|
36
|
|
|
description: '101 = 2', |
|
37
|
|
|
input: [true, false, true], |
|
38
|
|
|
expectedResult: 2, |
|
39
|
|
|
}, |
|
40
|
|
|
{ |
|
41
|
|
|
description: '110 = 2', |
|
42
|
|
|
input: [true, true, false], |
|
43
|
|
|
expectedResult: 2, |
|
44
|
|
|
}, |
|
45
|
|
|
{ |
|
46
|
|
|
description: '111 = 3', |
|
47
|
|
|
input: [true, true, true], |
|
48
|
|
|
expectedResult: 3, |
|
49
|
|
|
}, |
|
50
|
|
|
]; |
|
51
|
|
|
|
|
52
|
|
|
describe.each(TestCasesResult)( |
|
53
|
|
|
'Test totalTrueInputs helper', |
|
54
|
|
|
({ description, input, expectedResult }) => { |
|
55
|
|
|
it(description, () => { |
|
56
|
|
|
const result = Helper.totalTrueInputs(input); |
|
57
|
|
|
expect(result).toBe(expectedResult); |
|
58
|
|
|
}); |
|
59
|
|
|
} |
|
60
|
|
|
); |
|
61
|
|
|
|
|
62
|
|
|
const ErrorTestCases = [ |
|
63
|
|
|
{ |
|
64
|
|
|
description: 'test input with a null value', |
|
65
|
|
|
input: null, |
|
66
|
|
|
expectedError: 'row isnt an array', |
|
67
|
|
|
}, |
|
68
|
|
|
{ |
|
69
|
|
|
description: 'test input with a string', |
|
70
|
|
|
input: 'not ok', |
|
71
|
|
|
expectedError: 'row isnt an array', |
|
72
|
|
|
}, |
|
73
|
|
|
]; |
|
74
|
|
|
|
|
75
|
|
|
describe.each(ErrorTestCases)( |
|
76
|
|
|
'Test totalTrueInputs helper exception test', |
|
77
|
|
|
({ description, input, expectedError }) => { |
|
78
|
|
|
it(description, () => { |
|
79
|
|
|
function testWrongInput() { |
|
80
|
|
|
Helper.totalTrueInputs(input); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
expect(testWrongInput).toThrowError(new Error(expectedError)); |
|
84
|
|
|
expect(testWrongInput).toThrowError(InvalidInputError); |
|
85
|
|
|
}); |
|
86
|
|
|
} |
|
87
|
|
|
); |
|
88
|
|
|
|